<template>
  <div class="region">
    <div class="contend">
      <div class="left">地区:</div>
      <ul>
        <li :class="{active:activeFlag==''}" @click="changeRegion('')">全部</li>
        <li :class="{active:activeFlag==item.value}" v-for="item in hospitalRegionArr" :key="item.id" @click="changeRegion(item.value)">{{ item.name }}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
//引入组合式api
import { onMounted, ref } from "vue";
//引入接口函数
import { reqGetHospitalLevel } from "@/api/home";
//引入接口约束
import { HospitalLevelData, HospitalLevelArr } from "@/api/home/type";
//存储医院地址信息
let hospitalRegionArr = ref<HospitalLevelArr>([]);
//控制高亮效果
let activeFlag = ref<string>('');
//接收自定义事件
let $emit = defineEmits(['getRegion'])
//挂载时获取医院地区信息
onMounted(()=>{
    hospitalRegion();
})
//获取医院地区数据
const hospitalRegion = async()=>{
    let reslut:HospitalLevelData = await reqGetHospitalLevel("beijin");
    if(reslut.code == 200) {
        hospitalRegionArr.value=reslut.data;
    }
    
}
//改变医院地区的回调
const changeRegion = (value:string)=>{
    activeFlag.value = value;
    //调用自定义事件
    $emit('getRegion',activeFlag.value)
}
</script>

<style scoped lang="scss">
.region {
  color: #7f7f7f;
  .left {
    margin-right: 10px;
    width: 40px;
  }
  .contend {
    display: flex;
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 8px;
        margin-bottom: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>
